(function(){
    angular.module('feibo.teacher.controller').controller('BigClassController', BigClassController);

    BigClassController.$inject = ['TeacherService'];

    function BigClassController(TeacherService){
        var vm = this;
        vm.data = {
            list: undefined,
            keyword: {
                name: false,
                wd_days: false,
                wd_hours: false,
                we_days: false,
                we_hours: false
            }
        };

        vm.initData = function(){
            vm.fetchClassType();
        };

        vm.sorting = function(keyword){
            var data = vm.data;

            data.list.sort(function(a, b){
                var x, y;
                if(a && b && typeof a === 'object' && typeof b === 'object'){

                    if(data.keyword[keyword]){
                        x = a[keyword];
                        y = b[keyword];
                    }else {
                        x = b[keyword];
                        y = a[keyword];
                    }

                    if(x == y){
                        return 0;
                    }else if(typeof x === typeof y){
                        return  x >  y ? 1 : -1;
                    }else {
                        return typeof x > typeof y ? 1 : -1;
                    }
                }
            });

            data.keyword[keyword] = !data.keyword[keyword];
        };

        vm.fetchClassType = function(){
            var queryConfig = {
                funcName: 'fetchClassType',
                container: vm.data,
                propName: 'list',
                propChain: ['data','entries'],
                showLoadLayer: false
            };

            TeacherService.fetchClassType(queryConfig).catch(function(error){
                console.error(error);
            });
        };
    }
}());
